Prizm Content Connect
Get Total Page Count File (getTotalPagesURL)

GetTotalPageCount file is called from ViewerEnterprise.swf and returns the actual number of pages in the document.

GetTotalPageCount file accepts document as a GET parameter and returns the pages.

Arguments:  fileName, documentname, instanceid

Returns:  pages=pagecount

VB.NET
Copy Code

<%@ WebHandler Language="VB" Class="GetTotalPageCount" %>

Imports System.Web
Imports System.IO
Imports System.Net
Imports System.Web.Configuration
Imports System.Web.SessionState

Public Class GetTotalPageCount
    Implements IHttpHandler
    Implements IReadOnlySessionState

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        ' Environmental Setup
        PccConfig.LoadConfig("prizmconfig.xml")

        Dim origDocument As String = context.Request.QueryString("fileName")
        Dim document As String = PccCommon.getDownloadedName(origDocument)
        Dim documentLocation As String = PccCommon.getDownloadedPath(origDocument)
        Dim tempLocation As String = PccConfig.TempFolder


        Dim originalDocument As String = System.IO.Path.Combine(documentLocation, document)
        Dim pageContent As String = ""

        If System.IO.File.Exists(originalDocument) Then
            Dim UniqueFileIdHash As String = PccCommon.getFileHash(documentLocation & document)
            Dim totalpagesFile As String = System.IO.Path.Combine(tempLocation, UniqueFileIdHash & "_" & document & "_totalpages.txt")
            If System.IO.File.Exists(totalpagesFile) Then
                Dim tr As TextReader = New StreamReader(totalpagesFile)
                pageContent = tr.ReadLine()
                tr.Close()
            End If
            If (pageContent Is Nothing Or pageContent.Trim().Equals("") Or pageContent.Trim().Equals("0")) Then
                Try
                    Dim HttpWReq As HttpWebRequest = DirectCast(WebRequest.Create(PccConfig.ImagingService + "/convert2swf?totalpages&source=" & HttpUtility.UrlEncode(originalDocument)), HttpWebRequest)
                    HttpWReq.Timeout = 660000
                    Dim HttpWResp As HttpWebResponse = DirectCast(HttpWReq.GetResponse(), HttpWebResponse)
                    Dim sr As New StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.UTF8)
                    pageContent = sr.ReadToEnd()
                    HttpWResp.Close()
                    sr.Close()
                    Dim tw As TextWriter = New StreamWriter(totalpagesFile)
                    tw.Write(pageContent)
                    tw.Close()
                Catch
                    pageContent = "1"                   
                End Try
               
            End If

            context.Response.Write("pages=" & pageContent)
        Else
            context.Response.Status = "404 Not Found"
            context.Response.StatusCode = 404
            context.Response.Write("Error")
        End If

    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback